﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Logistics_Service.DTO;

namespace Logistics_Service.DAO
{
    public class DiaDiemDAO
    {
        public DiaDiemDTO[] DanhSachDiaDiem()
        {
            DiaDiemDTO[] arr;
            string query = string.Format("select * from ChiNhanh");
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);
            int n = dt.Rows.Count;
            arr = new DiaDiemDTO[n];
            for (int i = 0; i < n; i++)
            {
                object kh = GetDataFromDataRow(dt, i);
                arr[i] = (DiaDiemDTO)kh;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            DiaDiemDTO dd = new DiaDiemDTO();
            dd.Ma = dt.Rows[i]["Ma"].ToString();
            dd.Ten = dt.Rows[i]["Ten"].ToString();
            dd.DiaChi = dt.Rows[i]["DiaChi"].ToString();
            dd.MaTinhThanh = dt.Rows[i]["MaTinhThanh"].ToString();
            dd.SDT = dt.Rows[i]["SDT"].ToString();
            dd.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());
            return (object)dd;
        }       
    }    
}